<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<style>
    div[lay-id="datalist"] .layui-table-cell{height:auto !important;};
    .laytp-container .xmselect_div{border-color: #eee;}
    input{border-color: #ccc !important;}
    .laytp-container xm-select{min-height: 36px !important;line-height: 36px !important;}
    .xmselect_title{font-size: 14px;line-height: 36px;padding-left: 5px;}
</style>
<body class="laytp-container">
    <div id="opt_nav">
    </div>

    <div class="layui-fluid layui-fluid_list">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card" style="padding-top: 20px;padding-bottom: 20px;">
                    <div class="layui-card-body">
                        <div class="layui-form layui-col-space5 search_fors">
                            <div class="layui-inline layui-show-xs-block">
<!--                                <select id="type" lay-filter="type"><option value="">证书分类</option></select>-->
                                <div id="type" class="xmselect_div" style="width: 195px;height: 36px;">
                                    <div class="xmselect_title">证书分类</div>
                                </div>
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <select id="name" multiple="multiple" lay-filter="name"><option value="">证书名称</option></select>
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <select id="major"><option value="">证书专业</option></select>
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <select id="status"><option value="">证书状态</option></select>
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <select id="sex"><option value="">性别</option></select>
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <select id="nature"><option value="">人员性质</option></select>
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <select id="social"><option value="">社保状态</option></select>
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <select id="month"><option value="">参保月份数</option></select>
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <select id="chanid"><option value="">归属公司</option></select>
                            </div>
                            人数：
                            <div class="layui-inline layui-show-xs-block">
                                <input type="number" id="person_num" value="1" class="layui-input">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn btn-dark" type="button" id="add_search_cond"><i class="layui-icon">&#xe608;</i>添加筛选条件</button>
                            </div>

                            <!--条件展示-->
                            <div style="border: 1px solid #e3e3e3;min-height: 150px;">
                                <div style="width: 100%;min-height: 100px;padding:10px 0px 0px 10px;" id="condition_list">
                                    <span id="tips" style="font-size:18px;color:#9c9c9c;">请先添加筛选条件</span>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block" style="margin-left: 40px;text-align:center;">
                                        <input type="radio" name="is_both" value="1" title="任意均可" checked lay-filter="is_both">
                                        <input type="radio" name="is_both" value="2" title="同时具备" lay-filter="is_both">
                                    </div>
                                </div>
                            </div>
                            <div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block" style="margin-left: 40px;text-align:center;">
                                        <button class="layui-btn btn-dark" id="search"><i class="layui-icon">&#xe615;</i>查询</button>
                                        <button class="layui-btn btn-dark" onclick="location.reload()" ><i class="layui-icon">&#xe633;</i>重置</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>


                    <div class="layui-card-body">
                        <span id="count_row" class="layui-hide">查出符合要求的证书有<span id="count_num">0</span>本</span>
                        <button class = "layui-btn layui-btn-sm btn-dark" lay-event="choose" id="choose"><i class="layui-icon">&#xe654;</i>加入已选</button>
                        <button class = "layui-btn layui-btn-sm btn-dark" lay-event="choose_ids" id="choose_ids">已选: 0</button>
                    </div>


                    <div class="layui-card-body">
                        <div id="datalist" lay-filter="datalist"></div>
                    </div>

                    <input type="hidden" id="change" value="">
                </div>
            </div>
        </div>
    </div>
</body>


<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
        <a href="javascript:;" class="bar_opt" lay-event="detail">更换</a>
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>

<script type="text/javascript">
    // 添加筛选条件
    var check_repeat_list = [];
    var list = [''];
    $('#add_search_cond').click(function () {
        // var type = $('#type').val(); // 证书分类
        // var type_s = $('#type option:selected').text();
        var type = sea_type;
        var type_s = sea_type_title;
        var name = $('#name').val(); // 证书名称
        var name_s = $('#name option:selected').text();
        var major = $('#major').val(); // 证书专业
        var major_s = $('#major option:selected').text();
        var status = $('#status').val(); // 证书状态
        var status_s = $('#status option:selected').text();
        var sex = $('#sex').val(); // 性别
        var sex_s = $('#sex option:selected').text();
        var nature = $('#nature').val(); // 人员性质
        var nature_s = $('#nature option:selected').text();
        var social = $('#social').val(); // 社保状态
        var social_s = $('#social option:selected').text();
        var month = $('#month').val(); // 参保月份数
        var month_s = $('#month option:selected').text();
        var chanid = $('#chanid').val(); // 所属公司
        var chanid_s = $('#chanid option:selected').text();
        var person_num = $('#person_num').val(); // 人员数量
        if(!type){
            layer.msg('请选择证书分类'); return false;
        }
        if(parseInt(person_num) < 1){
            layer.msg('人数必须大于1'); return false;
        }
        // 页面展示
        var check_repeat_str = '';
        check_repeat_str += type_s;
        check_repeat_str += (!name) ? ',证书名称不限' : ','+name_s;
        check_repeat_str += (!major) ? ',证书专业不限' : ','+major_s;
        check_repeat_str += (!status) ? ',证书状态不限' : ','+status_s;
        check_repeat_str += (!social) ? ',社保状态不限' : ','+social_s;
        check_repeat_str += (!month) ? ',参保月份数不限' : ','+month_s;
        check_repeat_str += (!sex) ? ',性别不限' : ','+sex_s;
        check_repeat_str += (!nature) ? ',人员性质不限' : ','+nature_s;
        check_repeat_str += ','+chanid_s;
        // 判断条件是否重复添加
        if($.inArray(check_repeat_str, check_repeat_list) !== -1){
            facade.error('查询添加不能重复'); return false;
        }else{
            check_repeat_list.push(check_repeat_str);
        }

        // 数据处理
        var arr = {
            type:type,
            name:name,
            major:major,
            status:status,
            social:social,
            month:month,
            sex:sex,
            nature:nature,
            chanid:chanid,
            person_num:person_num
        };
        list.push(arr);

        // 页面展示
        $('#condition_list').append('<div check_repeat='+check_repeat_str+'>'+check_repeat_str+','+person_num+'人&nbsp;&nbsp;' +
            '<span style="color:red;cursor:pointer;" class="del_condition">X</span></div>');
        // 隐藏条件提示
        $('#tips').addClass('layui-hide');
    });

    // 删除筛选条件
    $('#condition_list').on('click','.del_condition',function () {
        var check_repeat_str = $(this).parent().attr('check_repeat');
        var index = $.inArray(check_repeat_str,check_repeat_list);
        check_repeat_list.splice(index,1);
        $(this).parent().remove();
        // 删除数据
        list.splice(index,1);
        // 显示添加条件的提示
        if(check_repeat_list.length == 0 || check_repeat_list.length == undefined){
            $('#tips').removeClass('layui-hide');
        }
    });

    // 子页面调用查询条件
    function set_list(){
        return list;
    }

    // 下载保存的id集合  判断是否有流程
    var idArr = [];  var flow = 0;
    // 下载页面删除，动态赋值
    function set_idArr(ids){
        idArr = ids;
        $('#choose_ids').html('已选：'+idArr.length);
    }
    // 子页面获取数据
    function get_idArr(){
        return idArr;
    }
    // 打开投标用证申请页面
    function open_cert_use_bid() {
        layer.closeAll();
        if(flow == 1){
            openPageEdit('../cert_use/flow_add.php?idArr='+JSON.stringify(idArr)+'&close=1&type=1');
        }else{
            openPageEdit('../cert_use/add.php?idArr='+JSON.stringify(idArr)+'&close=1&type=1');
        }
    }

    var sea_type = '', sea_type_title='';
    var is_hide = false;
    layui.use(['form','element','table'],function() {
        var form = layui.form;
        var table = layui.table;

        // 初始化数据
        facade.ajax({type: 'get', url: ask_cert_matching_list}).done(function(e){
            if (e.code === 2000) {
                flow = e.data.flow;

                xmselect_dan('type', e.data.type, sea_type, function (res) {
                    $('.xm-tips').html('证书分类');
                    sea_type = res.arr && res.arr.length > 0 ?  res.arr[0].value : '';
                    sea_type_title = res.arr && res.arr.length > 0 ? res.arr[0].name : '';

                    if(res.arr && res.arr.length > 0){
                        facade.ajax({type: 'get', url: ask_cert_form_name_list,data:{type:res.arr[0].value}}).done(function(e){
                            if (e.code === 2000) {
                                var cert_name = e.data;
                                var cert_name_str = '<option value="">证书名称</option>';
                                for (var i=0;i<cert_name.length;i++){
                                    cert_name_str += '<option value="'+cert_name[i]+'">'+cert_name[i]+'</option>';
                                }
                                $('#name').html(cert_name_str);
                                $('#major').html('<option value="">证书专业</option>');
                                render_from();
                            }
                        });
                    }
                });
                $('.xm-tips').html('证书分类');


                // 社保状态
                var socialArr = e.data.social;
                var social_str= '<option value="">社保状态</option>';
                for (var i=0;i<socialArr.length;i++){
                    social_str += '<option value="'+socialArr[i].value+'">'+socialArr[i].name+'</option>';
                }
                $('#social').html(social_str);

                // 证书状态
                var statusArr = e.data.status;
                var status_str= '<option value="">证书状态</option>';
                for (var i in statusArr){
                    status_str += '<option value="'+i+'">'+statusArr[i]+'</option>';
                }
                $('#status').html(status_str);

                // 参保月份数
                var monthArr = e.data.month;
                var month_str= '<option value="">参保月份数</option>';
                for (var i in monthArr){
                    month_str += '<option value="'+i+'">'+monthArr[i]+'</option>';
                }
                $('#month').html(month_str);

                // 性别
                var sexArr = e.data.sex;
                var sex_str= '<option value="">性别</option>';
                for (var i in sexArr){
                    sex_str += '<option value="'+sexArr[i]+'">'+sexArr[i]+'</option>';
                }
                $('#sex').html(sex_str);

                // 人员性质
                var natureArr = e.data.nature;
                var nature_str= '<option value="">人员性质</option>';
                for (var i=0;i<natureArr.length;i++){
                    nature_str += '<option value="'+natureArr[i].value+'">'+natureArr[i].name+'</option>';
                }
                $('#nature').html(nature_str);

                // 所属公司
                var chanidArr = e.data.chanid;
                var chanid_str = '<option value="">归属公司</option>';
                for (var i=0;i<chanidArr.length;i++){
                    chanid_str += '<option value="'+chanidArr[i].id+'">'+chanidArr[i].name+'</option>';
                }
                $('#chanid').html(chanid_str);
                render_from();
            }
        });

        $('#cols_table').hide();
        $('#export_table').hide();
        $('#search_table').hide();
        table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_cert_matching_list)
            ,where: {is_both:0}, page: false, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response
            ,text: TabInit.text
            ,parseData: function (res) {
                currButAuth = res.data.butauth;
                tableButShow(currButAuth);

                $('#count_num').text(res.data.count);
                $('#count_row').removeClass('layui-hide');

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "data": res.data.data
                };
            }
            ,cols: [[
                {type: 'checkbox',fixed:'left'}
                ,{type: 'numbers', title: '序号',fixed:'left'}
                ,{field: 'person_name', title: '持证人',event:'person_name',templet:function (e) {
                        return '<a class="colorlan">'+e.person_name+'</a>';
                    }}
                ,{field: 'nature', title: '人员性质'}
                ,{field: 'cert_name', title: '证书名称',event:'cert_name',templet:function (e) {
                    return '<a class="colorlan">'+e.cert_name+'</a>';
                }}
                ,{field: 'number', title: '证书编号'}
                ,{field: 'major', title: '证书专业'}
                ,{field: 'expiry_dt', title: '有效期'}
                ,{field: 'issue_unit', title: '发证单位'}
                ,{field: 'chanid_name', title: '归属公司'}
                ,{field: 'goes', title: '证书去向'}
                ,{field: 'status', title: '证书状态'}
                ,{field: 'state', title: '人员状态'}
                ,{field: 'social', title: '社保状态'}
                ,{fixed: 'right', title:'操作', toolbar: '#test-dropdown-toolbar-barDemo',align:'center',width:200}
            ]]
            , done: function (res) {
                // soulTable.render(this);

                // currTabData = res.data;
                // $.each(currTabData, function(index,item){
                //     var chk = $('tr[data-index=' + item.LAY_TABLE_INDEX + '] .tab-list-authbut');
                //     for (var key in currButAuth) {
                //         if(currButAuth[key].pagetype === 0 || currButAuth[key].pagetype === 1){
                //             chk.append(' <a ' +
                //                 'href="javascript:;" ' +
                //                 'class="bar_opt layui-hide" ' +
                //                 'lay-event="search" ' +
                //                 'data-butname="'+currButAuth[key].butname+'" ' +
                //                 'data-title="'+currButAuth[key].title+'" ' +
                //                 'onclick="auth_but_func_'+currButAuth[key].butname+'(\''+currButAuth[key].title+'\', '+index+')"' +
                //                 '>'+currButAuth[key].title+'' +
                //                 '</a>');
                //         }
                //     }
                // });
                // show_tab_but(currTabData);

                // 处理列表fixed的高度问题
                $('div[lay-id="datalist"] .layui-table-main>table>tbody>tr').each(function (i) {
                    var height = $(this).height();
                    $('div[lay-id="datalist"] .layui-table-fixed-l>.layui-table-body>table>tbody>tr')
                        .eq(i).css('cssText','height:'+height+'px !important');
                    $('div[lay-id="datalist"] .layui-table-fixed-r>.layui-table-body>table>tbody>tr')
                        .eq(i).css('cssText','height:'+height+'px !important');
                });
            }
        });


        // 详情
        table.on('tool(datalist)',function (obj) {
            var data = obj.data;
            if(obj.event === 'cert_name'){
                openPage('../cert/show.php?id='+data.id,'100%','100%');
            }else if (obj.event === 'cert_status'){
                openPage('../cert/engin_build.php?id='+data.id,'100%','100%');
            }else if(obj.event === 'detail'){
                layer.open({
                    type: 2,
                    title: '选择证书',
                    area: ['90%', '90%'],
                    maxmin: true,
                    content: 'change.php',
                    end: function () {
                        var change = $('#change').val();
                        var change_data = JSON.parse(change);
                        obj.update(change_data);
                    }
                });
            }else if(obj.event === 'person_name'){
                open_page('../cert_person/show.php?id='+data.personid,'人员详情');
            }
        });


        $('#choose').click(function () {
            var checkStatus = table.checkStatus('datalist');
            var data = checkStatus.data;
            if(data.length === 0){
                layer.msg('请选择证书');return false;
            }
            for(var i=0;i<data.length;i++){
                idArr.push(data[i].id)
            }
            $.unique(idArr.sort())
            $('#choose_ids').html('已选：'+idArr.length);
        });
        $('#choose_ids').click(function () {
            if(idArr.length === 0){
                layer.msg('请选择证书');return false;
            }
            open_page('alloc.php','加入申请');
        });

        // 查询证书，刷新列表
        $('#search').on('click', function(){
            if(list.length === 1){
                layer.msg('请添加查询条件');return false;
            }
            // 获取查询方式 1任意均可 2同时具备
            var is_both = $('input[name="is_both"]:checked').val();
            if(is_both == 1){
                is_hide = false;
            }else{
                is_hide = true;
            }
            table.reload('datalist', {
                where:{
                    is_both:is_both,
                    list: list,
                }
            });
            $('#choose_ids').html('已选：'+idArr.length);
        });

        // 证书分类改变事件
        form.on('select(type)', function(data){
            var id = data.value;
            facade.ajax({type: 'get', url: ask_cert_form_name_list,data:{type:id}}).done(function(e){
                if (e.code === 2000) {
                    var cert_name = e.data;
                        var cert_name_str = '<option value="">证书名称</option>';
                        for (var i=0;i<cert_name.length;i++){
                            cert_name_str += '<option value="'+cert_name[i]+'">'+cert_name[i]+'</option>';
                        }
                        $('#name').html(cert_name_str);
                        $('#major').html('<option value="">证书专业</option>');
                        render_from();
                }
            });
        });

        // 证书名称改变事件
        form.on('select(name)', function(data){
            var name = data.value;
            facade.ajax({type: 'get', url: ask_cert_form_major_list,data:{name:name,type:sea_type}}).done(function(e){
                if (e.code === 2000) {
                    var cert_major = e.data;
                    var cert_major_str = '<option value="">证书专业</option>';
                    for (var i in cert_major){
                        cert_major_str += '<option value="'+cert_major[i]+'">'+cert_major[i]+'</option>';
                    }
                    $('#major').html(cert_major_str);
                    render_from();
                }
            });
        });

        // 1任意均可 2同时具备
        form.on('radio(is_both)', function(data){
            if(data.value == 1){
                is_hide = false;
            }else{
                is_hide = true;
            }
        });

    });
</script>
</html>















